﻿#region

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;

#endregion

namespace pushbomb.composite.core.DynamicObject
{
    [CollectionDataContract(IsReference = true)]
    public sealed class ExtensionCollection : Collection<IExtension<DynamicObject>>, IExtensionCollection
    {

        public ExtensionCollection(IEnumerable<IExtension<DynamicObject>> extensions)
        {
            if (extensions != null)
                foreach (var x in extensions)
                {
                   
                    Add(x);
                }
        }

        #region IExtensionCollection<DynamicObject> Members

        public TE Find<TE>()
        {
            return this.OfType<TE>().FirstOrDefault();
        }

        public Collection<TE> FindAll<TE>()
        {
            return new Collection<TE>(this.OfType<TE>().ToList());
        }

        /// <summary>
        /// Gets a value indicating whether the <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only.
        /// </summary>
        /// <value></value>
        /// <returns>true if the <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only; otherwise, false.</returns>
        public bool IsReadOnly
        {
            get
            {
                return false;

            }
        }

        #endregion
    }
}